package d2;
import java.util.*;
class Node {
    public int val;
    public List<Node> children;

    public Node() {}

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
};
public class Day2 {
    //最长等差数列
    public int longestArithSeqLength(int[] nums) {
        int n = nums.length;
        int[][] dp = new int[n][n];
        Map<Integer,Integer> hash = new HashMap<>();
        int ret = 2;
        for(int i=0;i<n;i++) {
            for(int j=i+1;j<n;j++) {
                dp[i][j]=2;
                int c = nums[i]-(nums[j]-nums[i]);
                int k = hash.getOrDefault(c,-1);
                if(k!=-1&&k<i) {
                    dp[i][j]=dp[k][i] + 1;
                    ret = Math.max(ret,dp[i][j]);
                }
            }
            hash.put(nums[i],i);
        }
        return ret;
    }
    //N叉树的层序遍历
    public List<List<Integer>> levelOrder(Node root) {
        List<List<Integer>> ret = new ArrayList<>();
        if(root==null) return ret;
        Queue<Node> queue = new LinkedList<>();
        queue.add(root);
        while (!queue.isEmpty()) {
            int size = queue.size();
            List<Integer> tmp = new ArrayList<>();
            while (size!=0) {
                Node t = queue.poll();
                tmp.add(t.val);
                for(Node child:t.children) {
                    queue.add(child);
                }
                size--;
            }
            ret.add(new ArrayList(tmp));
        }
        return ret;
    }



}
